package com.youhome.service.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.youhome.common.exception.CustomException;
import com.youhome.service.mapper.HouseThemeMapper;
import com.youhome.service.model.HouseTheme;
import com.youhome.service.service.HouseThemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by chen365 on 2018/03/09.
 */
@Service
public class HouseThemeServiceImpl implements HouseThemeService {
    @Autowired
    private HouseThemeMapper houseThemeMapper;

    @Override
    public PageInfo<HouseTheme> selectByBean(Integer pageIndex, Integer pageSize, HouseTheme theme) {
        if (pageIndex == null || pageIndex < 1)
            pageIndex = 1;
        if (pageSize == null || pageSize < 1)
            pageSize = 20;

        PageHelper.startPage(pageIndex, pageSize);
        List<HouseTheme> list = houseThemeMapper.selectByBean(theme);
        return new PageInfo<>(list);
    }

    @Override
    public HouseTheme selectByPrimaryKey(Long themeId) {
        return houseThemeMapper.selectByPrimaryKey(themeId);
    }

    @Override
    public PageInfo<HouseTheme> selectByBean(Integer pageNumber, Integer pageSize) throws CustomException {
        HouseTheme theme = new HouseTheme();
        theme.setStatus(true);
        if (pageNumber == null || pageNumber < 1) {
            pageNumber = 1;
        }
        if (pageSize == null || pageSize < 1) {
            pageSize = 20;
        }
        PageHelper.startPage(pageNumber, pageSize);
        List<HouseTheme> list = houseThemeMapper.selectByBean(theme);
        return new PageInfo<>(list);
    }
}
